<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class ProductSaleMonth extends Model
{
    //
    protected $table = 'product_sale_months';

    protected $fillable = [
        'product_id', 'sale_count', 'total_amount', 'month', 'year'
    ];

    public function scopeMonth($query, $month) {
        if(!empty($month)) {
            return $query->where('month', $month);
        }
        return $query;
    }

    public function scopeYear($query, $year) {
        if(!empty($year)) {
            return $query->where('year', $year);
        }
        return $query;
    }

    public function scopeProductId($query, $product_id) {
        if(!empty($product_id)) {
            return $query->where('product_id', $product_id);
        }
        return $query;
    }

    public function product() {
        return $this->belongsTo('\App\Model\Product');
    }
}
